# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=FileZilla
pkgbase=mingw-w64-filezilla
pkgname=("${MINGW_PACKAGE_PREFIX}-filezilla")
pkgver=3.51.0
pkgrel=1
pkgdesc="Fast and reliable FTP, FTPS and SFTP client (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://lib.filezilla-project.org/"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-libfilezilla"
         "${MINGW_PACKAGE_PREFIX}-wxWidgets")
license=('GPL')
source=("${_realname}-${pkgver}.tar.bz2"::"https://download.filezilla-project.org/client/${_realname}_${pkgver}_src.tar.bz2"
        "0001-fix-datadir-lookup.patch")
sha256sums=('82be1c4a4f51bb32a599d0b4cc3a24127ba948c0af0f957233cc6a13ea3b6c4c'
            '793fa75ab742087aa8c98d05414b152a48ba244dc715d02563c8450399f27bab')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}/0001-fix-datadir-lookup.patch"
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --disable-manualupdatecheck \
    --disable-autoupdatecheck \
    --with-pugixml=builtin \
    --with-wx-config=${MINGW_PREFIX}/bin/wx-config

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  # LANG needed to fix string_test::test_conversion2
  LANG=en_US.UTF-8 make check || true
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
